import commit from './commit';
import publish from './publish';
import expansion from './expansion';
import ExtractDictByPDF from './ExtractDictByPDF';
import logger from '../utils/logger';

export default async () => {
  const cmd = await logger.prompt('🎖️   请选择以下能力', {type: 'select', options: [
    {value: 'commit1',            label: '🩷    提交代码',              hint: '规范化git—commit内容'},
    {value: 'commit2',            label: '🧡   提交代码并保存日志',     hint: '规范化git—commit内容并将留存日志'},
    {value: 'publish',            label: '❤️    发布包至npm',           hint: '支持仅发布某个子文件夹（如果可以的话，还是使用files字段控制！）'},
    {value: 'expansion',          label: '💛   依据配置展开拉取代码库', hint: '搞多环境代码同步用的'},
    {value: 'ExtractDictByPDF',   label: '🖤   从PDF抓取单词',          hint: '需要标准pdf'},
  ]})

  switch (String(cmd)) {
    case 'commit1':
      commit();
      break;
    case 'commit2':
      const versionLogPath = await logger.prompt('请输入日志保存路径', {type: 'text', default: '/version.log', placeholder: '/version.log'});
      commit(versionLogPath);
      break;
    case 'publish':
      const childFolderPath = await logger.prompt('若仅提交某子文件夹，则输入，反之，则回车继续发布', {type: 'text', placeholder: '/dist'})
      publish(childFolderPath)
      break;
    case 'expansion':
      const repoConfPath = await logger.prompt('请输入配置文件路径', {type: 'text', placeholder: '/repo.mapping.json', default: '/repo.mapping.json'})
      if (!repoConfPath) logger.error('请检查配置文件路径是否正确！');
      else expansion(repoConfPath)
      break;
    case 'ExtractDictByPDF':
      const pdfPath = await logger.prompt('请输入配置文件路径', {type: 'text', placeholder: './*.pdf'})
      if (!pdfPath) logger.error('请检查配置文件路径是否正确！');
      else ExtractDictByPDF(pdfPath)
      break;
    default:
      break;
  }
}